package router

import (
	"ginx/internal/global/configs"
	"ginx/internal/middleware"

	"github.com/gin-gonic/gin"
)

func Engine(mode string) {
	gin.SetMode(mode)
	r := gin.New()

	// 捕获panic、统一响应、日志、cors跨域
	r.Use(gin.Recovery(), middleware.SystemLogger(), middleware.Cors(), middleware.RateLimitByUser(), middleware.AccessCount())

	// 设置路由
	InitRouters(r)

	// 启动服务
	gracefulNew(r, configs.C).Run()
}
